package com.yc.cloud.security.dto;

import com.yc.cloud.entity.MemberAccount;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;

/**
 * SpringSecurity需要的用户详情
 * Created by macro on 2018/4/26.
 */
@Data
public class MemberUserDetails implements UserDetails {
    //后台用户
    private MemberAccount memberAccount;


    public MemberUserDetails(MemberAccount memberAccount) {
        this.memberAccount = memberAccount;
    }


    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        //返回当前用户的角色
        return null;
    }

    @Override
    public String getPassword() {
        return memberAccount.getPassword();
    }

    @Override
    public String getUsername() {
        return memberAccount.getUsername();
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return memberAccount.getStatus().equals(1);
    }

}
